﻿@using Utils;
@model WebUI.Models.JobListViewModel
@{
    ViewBag.Title = "Manage Jobs - JuicyBasket";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<div class="mainCol">
    <div class="profile">
        <div class="fl">
            <a href="@Url.Action("JobList")" title="@Model.Co.Name">
                <img class="avatar80" src="@Url.StaticFile(Model.AvatarUrl)" alt="@Model.Co.Name"/>
            </a>
        </div>
        <div class="fl">
            <h1>
                <span>@Model.Co.Name</span>
            </h1>
            
            <div class="profile-detail">
                @if (!string.IsNullOrEmpty(Model.Co.Location))
                {
                <div class="fl">
                    <a href="#" class="locality">@Model.Co.Location</a>
                </div>
                }
                @if (!string.IsNullOrEmpty(Model.Co.CoUrl))
                {
                <div class="fl">
                    <a href="@Model.Co.CoUrl" class="url" target="_blank">@Model.Co.CoUrl.ToDomainName()</a>
                </div>
                }
            </div>
            <div class="clear"></div>
            <div>
                <a class="action editaccount" href="/company/editprofile">
                    <span>Edit Account</span>
                </a>
            </div>
            <div class="clear"></div>
        </div>
    </div>
    <ul class="tabs">
        <li class="active">
            <a href="@Url.Action("JobList")">Jobs</a>
        </li>
        <li>
            <a href="@Url.Action("BillingHistory")">Billing History</a>
        </li>
        <li>
            <a href="@Url.Action("SavedTalent")">Saved Talent</a>
        </li>
        <li>
            <a href="@Url.Action("SavedJobs")">Saved Jobs</a>
        </li>
    </ul>
    <div class="tabsbottom"></div>
    <div class="clear"></div>
    @if (Model.JobList.Count > 0)
    {
        <div class="joblist">
            <div class="jobrow jobrowtitle">
                
                <div class="jobcol jobcol3">Job Title</div>
                <div class="jobcol jobcol4">Listing Status</div>
                
                <div class="jobcol jobcol1">Date Created</div>
                <div class="jobcol jobcol2">Date Published</div>
                <div class="jobcol jobcol5">Action</div>
            </div>
            @foreach (var job in Model.JobList)
            {
                string statusClass = "green";
                if (job.Status == 0)
                {
                    statusClass = "orange";
                }
                else if (job.Status == 2)
                {
                    statusClass = "red";
                }

                string publishDateString = string.Empty;
                if (job.Status != 0 && job.PublishDate != null)
                {
                    publishDateString = job.PublishDate.ToDateTimeString();
                }
                
                <div class="jobrow">

                    <div class="jobcol jobcol3">
                        @if (job.Status == 1)
                        {
                            <a href="/jobs/@job.JobID/@CommonUtilities.GetTitleInUrl(job.Title)">@job.Title.ToUpperAllFirstLetter()</a>
                        }
                        else
                        {
                            @job.Title.ToUpperAllFirstLetter()
                        }
                    </div>
                    <div class="jobcol jobcol4"><span class="@statusClass">@job.ListingStatus</span></div>
                    
                    <div class="jobcol jobcol1">@job.CreateDate.ToDateTimeString()</div>
                    <div class="jobcol jobcol2">@publishDateString</div>
                    <div class="jobcol jobcol5">
                        @if (job.Status == 1)
                        {
                            if (job.Editable)
                            {
                                <a href="/job/edit?jobtoken=@job.JobToken">Editable (in @job.EditableHours hours)</a> 
                            }
                            else
                            {

                            }
                        }
                        else if (job.Status == 0)
                        {
                            <a href="/job/post?jobtoken=@job.JobToken">Publish</a>
                        }
                        
                    </div>
                </div>
                
                <div class="clear"></div>
                
            }
        </div>
        
        <div class="clear"></div>
        <div class="page">
            <div class="paging">
            @if (Model.PreviousPage > 0)
            {
                <a href="@Url.Action("JobList", new {T = Model.FilterType, Page = Model.PreviousPage })" class="action pagingaction" rel="prev">← Newer</a>
            }
            @if (Model.NextPage > 0)
            {
                <a href="@Url.Action("JobList", new { T = Model.FilterType, Page = Model.NextPage })" class="action pagingaction" rel="next">Older →</a>
            }
            </div>
        </div>
    }
    else
    { 
    <div class="null-message">
        @if (Model.Page > 1)
        { 
            <h2>No more @Model.FilterType jobs</h2>
        }
        else
        {
            if (Model.FilterType == "unpublished")
            {
	            <h2>No unpublished jobs</h2>
            }
            else if (Model.FilterType == "expired")
            { 
                <h2>No expired jobs</h2>
            }
            else if (Model.FilterType == "active")
            { 
                <h2>No active jobs, <a href="/job/post">Create a listing</a> now </h2>
            }
            else
            { 
                <h2>No jobs, <a href="/job/post">Create a listing</a> now </h2>
            }
        }
    </div>
    }
    <div class="clear"></div>
</div>
<div class="sideCol">
    <div class="profile">
        <div class="jbblock">
            Remaining Job Credits: <span class="blue">@Model.Co.JobCredits</span>
        </div>
        <div class="clear"></div>
        <div class="smallspacer"></div>
        <div>
            <a class="action postjob" href="/job/post">
                <span>Post a Job</span>
            </a>
            <a class="action buycredits" href="/job/buycredits">
                <span>Buy Job Credits</span>
            </a>
        </div>
        
    </div>
    <div class="clear"></div>
    <ul class="tabs">
        <li>
            <h3><span>Job Filter</span></h3>
        </li>
    </ul>
    <div class="tabsbottom"></div>
    <div class="jobfilter">
        @if (string.IsNullOrEmpty(Model.FilterType))
        {
            <a href="/company/joblist" class="active">All Jobs</a>
        }
        else
        { 
            <a href="/company/joblist">All Jobs</a>
        }
        @if (Model.FilterType == "active")
        {
            <a href="/company/joblist?t=active" class="active">Active Only</a>
        }
        else
        { 
            <a href="/company/joblist?t=active">Active Only</a>
        }
        @if (Model.FilterType == "unpublished")
        {
            <a href="/company/joblist?t=unpublished" class="active">Unpublished Only</a>
        }
        else
        { 
            <a href="/company/joblist?t=unpublished">Unpublished Only</a>
        }
        @if (Model.FilterType == "expired")
        {
            <a href="/company/joblist?t=expired" class="active">Expired Only</a>
        }
        else
        { 
            <a href="/company/joblist?t=expired">Expired Only</a>
        }
    </div>
    <div class="clear"></div>
</div>